package com.yycwxt.common;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Mr.Zhang on 2022/8/29 20:59
 */
@RestController
@RequestMapping("/data")
public class DataController {


    @GetMapping("/account_date")
    public String getData() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Date date = new Date();
        return sdf.format(getLastDate(date));
    }



    private Date getLastDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH, -1);
        return cal.getTime();
    }

    public class Data {

        public static String getAccountDate() {
            return LocalDateTime.now().minusMonths(1).format(DateTimeFormatter.ofPattern("YYYY-MM"));
        }

        public static void main(String [] args) {
            System.out.println(getAccountDate());
        }

    }

}

